/**
 * 17/nov/2011 - fabio.melillo@gmail.com
 */
package unisannio.fm.interactive;

import java.util.ArrayList;

import unisannio.fm.R;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

/**
 * @author fabio
 *
 */
public class QuestionReceiver extends BroadcastReceiver {

	ArrayList<String> risultati=new ArrayList<String>();
	private boolean active;
	
	@Override
	public void onReceive(Context context, Intent intent) {
		if(active){
			final Context act=context;
			//DA FARE COMPLETAMENTE
			Bundle results=getResultExtras(true);
			String action=intent.getAction();
			String domanda=results.getString(HelpMeActivity.questionKey);
			NotificationManager nm=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
			String title="Question for you";
			int icon = R.drawable.ic_notification_hm;
			CharSequence tickerText = title;
			long when = System.currentTimeMillis();
			
			Notification notification = new Notification(icon,tickerText,when);
			notification.defaults=Notification.DEFAULT_ALL;
			CharSequence contentTitle = title;
			CharSequence contentText = domanda;
//			Intent notificationIntent = new Intent(context, ResponseActivity.class);
			Intent notificationIntent = intent;
			notificationIntent.setClass(context, ResponseActivity.class);
			notificationIntent.putExtra(HelpMeActivity.questionKey, domanda);
			notificationIntent.putExtra("action", action);
			
			notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
			PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
			notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
			notification.flags |= Notification.FLAG_AUTO_CANCEL;
			nm.notify(1, notification);
		}
	}
	
	public void reset(){
		risultati.clear();
	}
	
	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

}				
